package com.youlai.quarkus.system.controller;


import com.youlai.quarkus.system.common.result.Result;
import com.youlai.quarkus.system.model.dto.CaptchaResult;
import com.youlai.quarkus.system.model.dto.LoginResult;
import com.youlai.quarkus.system.service.AuthService;
import jakarta.ws.rs.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;

@Tag(name = "01.认证中心")
@Path("/api/v1/auth")
@RequiredArgsConstructor
@Slf4j
public class AuthController {

    private final AuthService authService;

    /**
     * 如果路径受quarkus.http.auth.限制，则使用@PermitAll不会打开路径。配置.为确保特定路径可访问，
     * 必须在Quarkus安全设置中进行适当的配置。
     *
     * @param username
     * @param password
     * @return
     */
    @Operation(summary = "登录")
    @POST
    @Path("login")
    public Result<LoginResult> login(
            @Parameter(description = "用户名", example = "admin") @FormParam("username") String username,
            @Parameter(description = "密码", example = "123456") @FormParam("password") String password,
            @Parameter(description = "验证码Code", example = "123456") @FormParam("verifyCode") String verifyCode,
            @Parameter(description = "验证码key", example = "123456") @FormParam("verifyCodeKey") String verifyCodeKey
    ) {
        return Result.success(authService.login(username, password, verifyCode, verifyCodeKey));
    }
    @Operation(summary = "注销")
    @Path("/logout")
    @DELETE
    public Result<Boolean> logout() {
        authService.logout();
        return Result.success();
    }

    @Operation(summary = "获取验证码")
    @Path("/captcha")
    @GET
    public Result<CaptchaResult> getCaptcha() {
        return Result.success(authService.getCaptcha());
    }

}
